import java.awt.*;
import java.awt.event.*;

public class Button {
	
	private GameInterface gi;
	private Menu owner;
	
	private String text;
	
	private boolean isEnabled;
	private boolean isHighlighted;
	
	private boolean mouseDown, mouseOver;
	private boolean keyDown;
	
	private int hotkey;
	
	private int x, y, width, depth;
	
	public Button(){}
	public Button(Menu cowner, String ctext, int chotkey, int cx, int cy, int cw, int cd){
		owner = cowner;
		text = ctext;
		hotkey = chotkey;
		x = cx;
		y = cy;
		width = cw;
		depth = cd;
		
		isEnabled = false;
		isHighlighted = false;
		mouseDown = false;
		mouseOver = false;
		keyDown = false;
	}
	
	public void update(long l){}
	public void display(Graphics2D g){}
	
	public boolean keyInput(KeyEvent ke){
		boolean tookInput = false;
		if(!getEnabled())
			return tookInput;
		if(hotkey == ke.getKeyCode())
		{
			tookInput = true;
			if(ke.getID() == 401)
			{
				setKeyDown(true);
			}
			if(ke.getID() == 402)
			{
				if(getKeyDown())
				{
					setKeyDown(false);
					activate();
				}
			}
		}
		return tookInput;
	}
	public boolean mouseInput(MouseEvent me){
		boolean tookInput = false;
		if(!getEnabled())
			return tookInput;

		int xtemp = (int)me.getPoint().getX();
		int ytemp = (int)me.getPoint().getY();

		if((xtemp < getX()+getWidth()) && (xtemp >= getX()))
		{
			if((ytemp < getY()+getDepth()) && (ytemp >= getY()))
			{
				tookInput = true;
				setMouseOver(true);
				if(me.getButton() == 1)
				{
					if(me.getID() == 501)
						setMouseDown(true);
					else if(me.getID() == 502)
					{
						if(getMouseDown())
						{
							setMouseDown(false);
							activate();
						}
					}
				}
			}
			else
			{
				setMouseOver(false);
				if(me.getID() == 502)
					setMouseDown(false);
			}
		}
		else
		{
			setMouseOver(false);
			if(me.getID() == 502)
				setMouseDown(false);
		}
		return tookInput;
	}
	
	public void activate(){}
	
	public GameInterface getGameInterface(){return gi;}
	public Menu getOwner(){return owner;}
	public String getText(){return text;}
	public boolean getEnabled(){return isEnabled;}
	public boolean getHighlighted(){return isHighlighted;}
	public boolean getMouseDown(){return mouseDown;}
	public boolean getMouseOver(){return mouseOver;}
	public boolean getKeyDown(){return keyDown;}
	public int getHotkey(){return hotkey;}
	public int getX(){return x;}
	public int getY(){return y;}
	public int getWidth(){return width;}
	public int getDepth(){return depth;}
	
	public void setGameInterface(GameInterface sgi){gi = sgi;}
	public void setOwner(Menu so){owner = so;}
	public void setText(String st){text = st;}
	public void setEnabled(boolean se){isEnabled = se;}
	public void setHighlighted(boolean sh){isHighlighted = sh;}
	public void setMouseDown(boolean smd){mouseDown = smd;}
	public void setMouseOver(boolean smo){mouseOver = smo;}
	public void setKeyDown(boolean skd){keyDown = skd;}
	public void setHotkey(int shotkey){hotkey = shotkey;}
	public void setX(int sx){x = sx;}
	public void setY(int sy){y = sy;}
	public void setWidth(int sw){width = sw;}
	public void setDepth(int sd){depth = sd;}
}
